package com.zfzs.post.modules.agentinfo.rest;

import com.zfzs.post.aop.log.Log;
import com.zfzs.post.common.bean.ResponseResult;
import com.zfzs.post.model.dto.QueryFindAgentInfoPageDTO;
import com.zfzs.post.model.dto.UpdateAgentInfoDTO;
import com.zfzs.post.modules.agent.service.AgentService;
import com.zfzs.post.modules.agentinfo.dto.ChannelDTO;
import com.zfzs.post.modules.agentinfo.service.AgentWebService;
import com.zfzs.post.modules.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 代理商管理
 *
 * @author ck
 * @date 2019-11-12
 */
@RestController
@RequestMapping("agents")
public class AgentWebController {

    @Autowired
    private AgentWebService agentInfosService;

    @Autowired
    private UserService userService;

    @Autowired
    private AgentService agentService;

    /**
     * 代理商列表
     *
     * @param criteria
     * @param page
     * @param size
     * @return
     */
    @Log("代理商列表")
    @GetMapping(value = "/agent_list")
    public ResponseResult getAgentInfoPage(QueryFindAgentInfoPageDTO criteria, Integer page, Integer size) {
        return ResponseResult.ok(agentInfosService.getAgentInfoPage(criteria, page, size));
    }

    /**
     * 查询渠道信息
     */
    @Log("查询渠道信息")
    @GetMapping(value = "/channel_list")
    public ResponseResult getChannelList() {
        return ResponseResult.ok(userService.geListChannelList());
    }

    /**
     * 修改
     *
     * @param resources
     * @return
     */
    @Log("修改")
    @PutMapping(value = "/update_agent")
    public ResponseResult updateAgent(@Validated @RequestBody UpdateAgentInfoDTO resources) {
        agentInfosService.updateAgentInfo(resources);
        return ResponseResult.ok();
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Log("删除")
    @DeleteMapping(value = "/delete/{id}")
    public ResponseResult delete(@PathVariable Long id) {
        agentInfosService.deleteAgentInfo(id);
        return ResponseResult.ok();
    }

    /**
     * 修改渠道信息
     * @param dto
     * @return
     */
    @Log("修改渠道信息")
    @PutMapping(value = "/update_channel")
    public ResponseResult updateChannel(@Validated @RequestBody ChannelDTO dto) {
        agentInfosService.updateChannel(dto);
        return ResponseResult.ok();
    }
}